﻿using System.Collections.Generic;
using Illinois.Core.Interfaces;
using Illinois.Core.Models;
using Illinois.Core.Services;
using Moq;
using NUnit.Framework;

namespace Illinois.Core.Test.Services
{
  [TestFixture]
  public class Test_Update_BurnDown_Metadata
  {
    private List<BurnDown> _list;
    private Mock<IBurnDownRepository> _repository;
    private const int BurnDownId = 101;
    private const string Title = "before";
    private const int Points = 30;

    [SetUp]
    public void Init()
    {
      _list = new List<BurnDown>();
      _list.Add(new BurnDown { Id = BurnDownId, Title = Title, InitialStoryPoints = Points });
      _repository = new Mock<IBurnDownRepository>();
    }

    [Test]
    public void I_Can_Update_The_Title() // wtf!
    {
      // arrange
      _repository.Setup(e => e.GetById(BurnDownId)).Returns(_list.Find(e => e.Id == BurnDownId));
      var service = new BurnDownService(_repository.Object);

      // act
      const string title = "after";
      const int error = 0;
      _repository.Setup(e => e.UpdateMetaData(BurnDownId, title, Points)).Returns(error);
      _list.Find(e => e.Id == BurnDownId).Title = title;
      var result = service.Edit(BurnDownId, title, Points);
      var burnDown = service.GetById(BurnDownId);

      // assert
      Assert.AreEqual(error, result);
      Assert.AreEqual(title, burnDown.Title);
    }
  }
}
